package com.lul15834.orderfood.until;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.lul15834.orderfood.R;
import com.lul15834.orderfood.bean.OrderBean;
import com.lul15834.orderfood.bean.OrderDetailBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 获取当前账号
 */
public class Tools {
    public static String getOnAccount(Context context){
        SharedPreferences sharedPreferences=context.getSharedPreferences("data", Context.MODE_PRIVATE);
        String businessId=sharedPreferences.getString("account","root");//如果这个值没有添加和使用则用默认的
        return businessId;
    }

    /**
     * 获取结果值当中的指定内容
     * @param rs
     * @param columnName
     * @return
     */
    @SuppressLint("Range")
    public static String getResultString(Cursor rs, String columnName){
        return rs.getString(rs.getColumnIndex(columnName));
    }

    /**
     * 输入表和名字，实现查询功能
     * @param list
     * @param query
     * @return
     */
    public static List<OrderBean> filterOrder(List<OrderBean> list,String query){
        List<OrderBean> list1=new ArrayList<>();
        for (OrderBean orderBean:list){//判断用户名是否有内容
            if (orderBean.getUserName().contains(query)){
                list1.add(orderBean);
            }else {
                List<OrderDetailBean> list2=orderBean.getOrderDetailBeans();//详情表
                for (OrderDetailBean orderDetailBean:list2){//判断食物名是否有内容
                    if (orderDetailBean.getFoodName().contains(query)){
                        list1.add(orderBean);
                    }
                }

            }
        }
        return list1;
    }

    /**
     * 动态展示星星
     * @param context
     * @param score
     * @param conId
     * @param starId
     */
    public static void setCommentStar(View context,int score,int conId,int starId[]){
        TextView con=context.findViewById(conId);//显示非常满意的内容
        //实现点击进行动态提示
        String conT[]={"非常差","差","一般","满意","非常满意"};//代表五个内容
        con.setText(conT[score-1]);
        for (int i=0;i<starId.length;i++){
            ImageView img=context.findViewById(starId[i]);
            img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //点击效果

                }
            });
        }


    }
}
